package com.ubhave.powertrackernof1;

import java.util.Date;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.wifi.WifiManager;
import android.os.BatteryManager;
import android.preference.PreferenceManager;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.Toast;

public class CallBroadcastReciever extends BroadcastReceiver{

	@Override
	public void onReceive(Context context, Intent intent) {
				
		String type="unknown";
		
		if(intent.getAction().equals("android.intent.action.PHONE_STATE")&&intent.getExtras().get(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_RINGING))
			type="Incomming";
		else if(intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL"))
			type="Outgoing";
		
		
		if(!type.equals("unknown")){
			Log.i("POWeR Tracker Sensor: ", "Call Event "+type);
			
					
			SharedPreferences settings;
			settings=PreferenceManager.getDefaultSharedPreferences(PowerTrackerApplication.getContext());
		
			if(settings.getBoolean("SensorsOn", false)){
				SharedPreferences.Editor editor = settings.edit();
				editor.putString("sensorLog", settings.getString("sensorLog", "")+"Push Sensor: Call("+type+") "+"TimeStamp("+new Date()+"), ");
        		editor.commit();
			}
		}
				
	}
	
	
	
}